package com.pz.cloud.framework.business.workflow.model;


import com.baomidou.mybatisplus.extension.service.IService;
import com.pz.cloud.framework.base.model.WorkflowEntity;
import com.pz.cloud.framework.business.workflow.entity.WaitDone;
import com.pz.cloud.framework.business.workflow.service.IWaitDoneService;
import org.jeecg.common.util.GenericUtil;
import org.jeecg.common.util.SpringContextUtils;


/**
 * 待办任务接口
 * @author mzz
 */
public interface WaitDoneTask<T extends WorkflowEntity,S extends IService<T>> {
    /**
     * 通过任务id获取对应业务实体
     * @param taskId
     * @return
     */
    default T getByTaskId(String taskId){
        IWaitDoneService waitDoneService = SpringContextUtils.getBean(IWaitDoneService.class);
        WaitDone waitDone = waitDoneService.getById(taskId);
        T obj = null;
        if(waitDone!=null){
            String bizId = waitDone.getBizId();
            obj = GenericUtil.getGeneric(this.getClass(), (generics) ->{
                    Class<IService<T>> serviceClass = (Class) generics[1];
                    IService<T> service = SpringContextUtils.getBean(serviceClass);
                    return service.getById(bizId);
            });
        }
        return obj;
    }
}
